<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<!--<html>-->
<head>
    <meta charset="utf-8"/>
    <title>登入 - layuiAdmin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link th:href="@{../static/layuiadmin/layui/css/layui.css}" rel="stylesheet">
    <link th:href="@{../static/layuiadmin/style/admin.css}" rel="stylesheet">
    <link th:href="@{../static/layuiadmin/style/login.css}" rel="stylesheet">
</head>
<body>
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>用户登录</h2>
                <p>权限管理系统</p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="useraccount"></label>
                    <input type="text" name="useraccount" id="useraccount" lay-verify="required" placeholder="用户账号" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="password"></label>
                    <input type="password" name="password"  id="password" lay-verify="required" placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                            <input type="text" name="captcha" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">

                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img src="/ams-admin/ams/captcha.jpg" class="layadmin-user-login-codeimg" id="LAY-user-get">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" style="margin-bottom: 20px;">
                    <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                    <a  class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？请联系管理员！</a>
                </div>
                <div >
                    <button class="layui-btn" style="width: 335px" id="denglu">登 录</button>
                </div>
                <div>
                    <a href="../templates/user/register.html" class="layadmin-user-jump-change layadmin-link" style="margin-top: 10px;">新用户注册</a>
                </div>
            </div>
        </div>
    </div>

    <!--<script src="/layuiadmin/layui/layui.js"></script>-->
    <script th:src="@{/static/layuiadmin/layui/layui.js}" rel="stylesheet"></script>
    <script>
        layui.config({
            base: '../static/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'layui/index' //主入口模块 lib/index
        }).use(['index', 'user'], function(){
            var $ = layui.$
                ,setter = layui.setter
                ,admin = layui.admin
                ,form = layui.form
                ,router = layui.router()
                ,search = router.search;

            form.render();

            $(document).on('click','#LAY-user-get',function(){
                var img=document.getElementById("LAY-user-get");
                img.src="/ams-admin/ams/captcha.jpg?"+new Date().getTime();
            });
            //调用后台登录
            $(document).on('click','#denglu',function() {
                event.preventDefault()

                var userInfo={
                    useraccount:$("#useraccount").val(),
                    password:$("#password").val(),
                    captcha:$("#LAY-user-login-vercode").val(),
                }
                $.post("./login", userInfo, function(res){
                    console.info("/ams/login+++++++++++++"+res);

                    if(res.code==500){

                        if (res.message=="账户密码为初始密码，请修改密码"){
                            location.href="./updatePassword"
                        }else{
                            //alert("账号或者密码错误")
                            layui.use('layer',function () {
                                var layer=layui.layer;
                                layer.msg(res.message, { icon: 2, offset: "auto", time:2000 })
                            })
                        }

                        var img=document.getElementById("LAY-user-get");
                        img.src="/ams-admin/ams/captcha.jpg?"+new Date().getTime();


                    }else{
                        var layer=layui.layer;
                        layer.msg('登录成功', {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        }, function(){
                            location.href = '../templates/welcome/index.html'; //跳转到登入页
                        });
                    }

                });

            });
            //iframe 层

        });
    </script>

</body>
</html>

